/*************************************************************
 * Title: WordFilterChain.java
 * Description: 
 * Author: Huang Shaobin
 * Email: shaobin.software@gmail.com
 * CreateTime: Oct 15, 2013 11:48:49 AM
 * Description:
 ************************************************************/
package snow.core.toolkit.filter;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;

/**
 *
 */
public class WordFilterChain {

	private boolean ending;
	private Map<Character, WordFilterChain> chainMap;

	public WordFilterChain() {
		this.chainMap = new HashMap<Character, WordFilterChain>();
	}

	public void clear() {
		if (MapUtils.isNotEmpty(chainMap)) {
			Collection<WordFilterChain> values = chainMap.values();
			if (CollectionUtils.isNotEmpty(values)) {
				for (WordFilterChain chain : values) {
					if (chain != null) {
						chain.clear();
					}
				}
			}
			chainMap.clear();
		}
	}
	
	public WordFilterChain getChainFrom(Character word) {
		return this.chainMap.get(word);
	}

	public boolean isEnding() {
		return ending;
	}

	public void putChainFrom(Character word, WordFilterChain chain) {
		this.chainMap.put(word, chain);
	}

	public void setEnding(boolean ending) {
		this.ending = ending;
	}

}
